package com.niiwoo.civet.trade.service.dubbo.loan;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.trade.dao.entity.SmallLoanWhiteUsers;
import com.niiwoo.civet.trade.dto.common.LoanBusinessInfoDTO;
import com.niiwoo.civet.trade.dto.common.SmallLoanWhiteUsersDTO;
import com.niiwoo.civet.trade.service.loan.LoanBusinessDubboService;
import com.niiwoo.civet.trade.service.local.loan.LoanBusinessLocalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by dell on 2018/4/18.
 * Description：civet-app
 */
@Slf4j
@Service(version = "1.0.0")
public class LoanBusinessDubboServiceImpl implements LoanBusinessDubboService {

    @Autowired
    private LoanBusinessLocalService loanBusinessLocalService;
    /**
     * 查询用户白名单
     * @param userId
     * @return
     */
    @Override
    public SmallLoanWhiteUsersDTO querySmallLoanWhite(String userId) {
        SmallLoanWhiteUsers smallLoanWhiteUsers = loanBusinessLocalService.querySmallLoanWhite(userId);

        log.info("querySmallLoanWhite.userId={},smallLoanWhiteUsers={}",userId, JSON.toJSONString(smallLoanWhiteUsers));

        if (smallLoanWhiteUsers==null) {
            return null;
        }

        SmallLoanWhiteUsersDTO smallLoanWhiteUsersDTO = new SmallLoanWhiteUsersDTO();
        BeanUtils.copyProperties(smallLoanWhiteUsers, smallLoanWhiteUsersDTO);

        return smallLoanWhiteUsersDTO;
    }

    /**
     * 获取借款产品列表
     * @return
     */
    @Override
    public List<LoanBusinessInfoDTO> getProductList() {
        return loanBusinessLocalService.getProductList();
    }

    /**
     * 获取产品配置
     */
    public LoanBusinessInfoDTO selectByProductType(Byte productType){
        return loanBusinessLocalService.selectByProductType(productType);
    }

}
